<template>
  <a-select
    class="selectBox"
    showSearch
    :filter-option="filterOption"
    placeholder="请选择变更后的受理单位"
    @change="selectChange"
  >
    <a-select-option v-for="item in prelist" :key="item.id" :value="item.id">
      {{ item.name }}
    </a-select-option>
  </a-select>
</template>

<script>
import { queryHa_departApiList } from '@/api/base/ha_depart.js'
export default {
  props: ['pattern'],
  data() {
    return {
      prelist: [],
    }
  },
  created() {
    // 管理员模式忽略查询条件
    if (this.pattern != 5) {
      let adid = this.$store.state.Processform.formData['apl_main#adid']
      if (!adid) {
        this.$message.error('未找到申请表的详细地址')
        return
      }
      this.getApiList(adid.substring(adid.indexOf(',') + 1, adid.indexOf(',') + 5))
    } else {
      this.getApiList('36')
    }
  },
  methods: {
    // 下拉框回调
    selectChange(value) {
      for (let v of this.prelist) {
        if (v.id == value) {
          this.$emit('f_setAcceptsectionid', { acceptsectionid: v.id, acceptsectionname: v.name })
          break
        }
      }
    },
    // 查询拟受理单位
    getApiList(adid) {
      // console.log('adid', adid)
      queryHa_departApiList(adid).then((res) => {
        console.log('拟受理单位', res)
        if (res.code == 0) {
          this.prelist = res.data
        }
      })
    },
    // 下拉框搜索
    filterOption(input, option) {
      return option.componentOptions.children[0].text.indexOf(input) >= 0
    },
  },
}
</script>

<style scoped>
.selectBox {
  width: 100%;
  margin-bottom: 20px;
}
</style>
